home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / muds / lpmud312.tar / lpmud312 / exec.h < prev    next >
C/C++ Source or Header  |  1991-12-12  |  6KB  |  144 lines

  1. /*
  2.  * A compiled program consists of several data blocks, all allocated
  3.  * contiguos in memory to enhance the working set. At the compilation,
  4.  * the blocks will be allocated separately, as the final size is
  5.  * unknow. When compilation is done, the blocks will be copied into
  6.  * the one big area.
  7.  *
  8.  * There are 5 different blocks of information for each program:
  9.  * 1. The program itself. Consists of machine code instructions for a virtual
  10.  *    stack machine. The size of the program must not be bigger than
  11.  *    65535 bytes, as 16 bit pointers are used. Who would ever need a bigger
  12.  *    program :-)
  13.  * 2. Function names. All local functions that has been defined or called,
  14.  *    with the address of the function in the program. Inherited functions
  15.  *    will be found here too, with information of how far up the inherit
  16.  *    chain that the function was defined.
  17.  * 3. String table. All strings used in the program. They are all pointers
  18.  *    into the shared string area. Thus, they are easily found and deallocated
  19.  *    when the object is destructed.
  20.  * 4. Table of variable names. They all point into the shared string table.
  21.  * 5. Line number information. A table which tells at what address every
  22.  *    line belongs to. The table has the same number of entries as the
  23.  *    programs has source lines. This is used at errors, to find out the
  24.  *    line number of the error.
  25.  * 6. List of inherited objects.
  26.  */
  27.  
  28. /*
  29.  * When an new object inherits from another, all function definitions
  30.  * are copied, and all variable definitions.
  31.  * Flags below can't explicitly declared. Flags that can be declared,
  32.  * are found with TYPE_ below.
  33.  *
  34.  * When an object is compiled with type testing NAME_STRICT_TYPES, all
  35.  * types are saved of the arguments for that function during compilation.
  36.  * If the #pragma save_types is specified, then the types are saved even
  37.  * after compilation, to be used when the object is inherited.
  38.  */
  39. #define NAME_INHERITED        0x1    /* Defined by inheritance */
  40. #define NAME_UNDEFINED        0x2    /* Not defined yet */
  41. #define NAME_STRICT_TYPES    0x4    /* Compiled with type testing */
  42. #define NAME_HIDDEN        0x8    /* Not visible for inheritance */
  43. #define NAME_PROTOTYPE        0x10    /* Defined by a prototype only */
  44.  
  45. struct function {
  46.     char *name;
  47.     unsigned short offset;    /* Address of function,
  48.                  * or inherit table index when inherited. */
  49.     unsigned short flags;    /* NAME_ . See above. */
  50.     unsigned short num_local;    /* Number of local variables */
  51.     unsigned short num_arg;    /* Number of arguments needed.
  52.                    -1 arguments means function not defined
  53.                    in this object. Probably inherited */
  54.     unsigned short function_index_offset;
  55.     /* Used so that it is possible to quickly find this function
  56.      * in the inherited program.
  57.      */
  58.     unsigned short type;    /* Return type of function. See below. */
  59. };
  60.  
  61. struct variable {
  62.     char *name;
  63.     unsigned short type;    /* Type of variable. See below. TYPE_ */
  64.     unsigned short flags;    /* Facts found by the compiler. NAME_ */
  65. };
  66.  
  67. struct inherit {
  68.     struct program *prog;
  69.     unsigned short function_index_offset;
  70.     unsigned short variable_index_offset;
  71. };
  72.  
  73. struct program {
  74.     int ref;                /* Reference count */
  75. #ifdef DEBUG
  76.     int extra_ref;            /* Used to verify ref count */
  77. #endif
  78.     char *program;            /* The binary instructions */
  79.     char *name;                /* Name of file that defined prog */
  80.     int  id_number;            /* used to associate information with
  81.                       this prog block without needing to
  82.                        increase the reference count     */
  83.     unsigned short *line_numbers;    /* Line number information */
  84.     struct function *functions;
  85.     char **strings;            /* All strings uses by the program */
  86.     struct variable *variable_names;    /* All variables defined */
  87.     struct inherit *inherit;        /* List of inherited prgms */
  88.     int total_size;            /* Sum of all data in this struct */
  89.     int heart_beat;            /* Index of the heart beat function.
  90.                      * -1 means no heart beat
  91.                      */
  92.     /*
  93.      * The types of function arguments are saved where 'argument_types'
  94.      * points. It can be a variable number of arguments, so allocation
  95.      * is done dynamically. To know where first argument is found for
  96.      * function 'n' (number of function), use 'type_start[n]'.
  97.      * These two arrays will only be allocated if '#pragma save_types' has
  98.      * been specified. This #pragma should be specified in files that are
  99.      * commonly used for inheritance. There are several lines of code
  100.      * that depends on the type length (16 bits) of 'type_start' (sorry !).
  101.      */
  102.     unsigned short *argument_types;
  103. #define INDEX_START_NONE        65535
  104.     unsigned short *type_start;
  105.     /*
  106.      * And now some general size information.
  107.      */
  108.     unsigned short program_size;    /* size of this instruction code */
  109.     unsigned short num_functions;
  110.     unsigned short num_strings;
  111.     unsigned short num_variables;
  112.     unsigned short num_inherited;
  113. };
  114.  
  115. extern struct program *current_prog;
  116.  
  117. /*
  118.  * Types available. The number '0' is valid as any type. These types
  119.  * are only used by the compiler, when type checks are enabled. Compare with
  120.  * the run-time types, named T_ interpret.h.
  121.  */
  122.  
  123. #define TYPE_UNKNOWN    0    /* This type must be casted */
  124. #define TYPE_NUMBER    1
  125. #define TYPE_STRING    2
  126. #define TYPE_VOID    3
  127. #define TYPE_OBJECT    4
  128. #define TYPE_ANY    5    /* Will match any type */
  129.  
  130. /*
  131.  * These are or'ed in on top of the basic type.
  132.  */
  133. #define TYPE_MOD_STATIC        0x0100    /* Static function or variable */
  134. #define TYPE_MOD_NO_MASK    0x0200    /* The nomask => not redefineable */
  135. #define TYPE_MOD_POINTER    0x0400    /* Pointer to a basic type */
  136. #define TYPE_MOD_PRIVATE    0x0800    /* Can't be inherited */
  137. #define TYPE_MOD_PROTECTED    0x1000
  138. #define TYPE_MOD_PUBLIC        0x2000  /* Force inherit through private */
  139. #define TYPE_MOD_VARARGS    0x4000    /* Used for type checking */
  140.  
  141. #define TYPE_MOD_MASK        (~(TYPE_MOD_STATIC | TYPE_MOD_NO_MASK |\
  142.                    TYPE_MOD_PRIVATE | TYPE_MOD_PROTECTED |\
  143.                    TYPE_MOD_PUBLIC | TYPE_MOD_VARARGS))
  144.